thin.imports('/public/home/resource/sms.js');
thin.imports('/public/configure/conf.pwd.js');

$(function() {
	$('#submit-editmobile').on('click', submitEditMobile);
	$('#submit-udpass').on('click', submitUdpass);
	$('#submit-repass').on('click', submitRepass);
});

var __getdata_pwdupdate = {},
	__getdata_pwdreset = {},
	__getdata_resetmobile = {};

function submitEditMobile() {
	var data_opt = {
		'new_mobile': $('#ipt-rm-mobile').val(),
		'code': $('#ipt-rm-code').val()
	}
	if(data_opt['new_mobile'] == '') {
		$.toptip('请输入手机号', 'error');
		return;
	} else if(data_opt['code'] == '') {
		$.toptip('请输入验证码', 'error');
		return;
	}
	__getdata_resetmobile['mobile'] = data_mobile;
	__getdata_resetmobile['new_mobile'] = data_opt.new_mobile;
	verifySMSCode(function() {
		factory.request('_member_resetmobile');
	});
}

function submitUdpass() {
	__getdata_pwdupdate = {
		'passport': $('#ipt-ud-passport').val(),
		'password': $('#ipt-ud-password').val(),
		'confpwd': $('#ipt-ud-confpwd').val()
	};
	if(__getdata_pwdupdate['passport'] == '') {
		$.toptip('请输入原密码', 'error');
		return;
	} else if(__getdata_pwdupdate['password'] == '') {
		$.toptip('请输入新密码', 'error');
		return;
	} else if(__getdata_pwdupdate['confpwd'] == '') {
		$.toptip('再次输入新密码', 'error');
		return;
	}
	$.showLoading();
	factory.request('_member_pwdupdate');
}

function submitRepass() {
	var data_opt = {
		'mobile': $('#ipt-re-mobile').val(),
		'code': $('#ipt-re-code').val(),
		'password': $('#ipt-re-password').val(),
		'confpwd': $('#ipt-re-confpwd').val()
	}
	if(data_opt['mobile'] == '') {
		$.toptip('请输入手机号', 'error');
		return;
	} else if(data_opt['code'] == '') {
		$.toptip('请输入验证码', 'error');
		return;
	} else if(data_opt['password'] == '') {
		$.toptip('请输入新密码', 'error');
		return;
	} else if(data_opt['confpwd'] == '') {
		$.toptip('再次输入新密码', 'error');
		return;
	}
	__getdata_pwdreset = data_opt
	verifySMSCode(function() {
		factory.request('_member_pwdreset');
	});
}

function __complete_resetmobile(res) {
	$.hideLoading();
	if(res.status == 201) {
		$.toast("修改成功", 960);
		setTimeout(function() {
			//checkLocation('member');
			cker('member', 'editmobile-tpl-view');
		}, 800);
	} else {
		$.toptip(res.error, 'error');
	}
}

function __complete_pwdupdate(res) {
	$.hideLoading();
	if(res.status == 201) {
		$.toast("修改成功", 960);
		setTimeout(function() {
			checkLocation('member');
		}, 800);
		$('#ipt-ud-passport').val('');
		$('#ipt-ud-password').val('');
		$('#ipt-ud-confpwd').val('');
	} else {
		$.toptip(res.error, 'error');
	}
}

function __complete_pwdreset(res) {
	$.hideLoading();
	if(res.status == 201) {
		$.toast("修改成功", 960);
		setTimeout(function() {
			//checkLocation('member');
			cker('member', 'repass-tpl-view');
		}, 800);
		/*$('#ipt-re-code').val('');
		$('#ipt-re-password').val('');
		$('#ipt-re-confpwd').val('');*/
	} else {
		$.toptip(res.error, 'error');
	}
}